package com.solcoo.merchant.ui.member;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.android.common.image.ImageLoader;
import com.android.common.util.DensityUtil;
import com.solcoo.merchant.R;
import com.solcoo.merchant.base.BaseListAdapter;
import com.solcoo.merchant.model.Member;

public class MemberAdapter extends BaseListAdapter<Member> {
	private ListView.LayoutParams layoutParams = new ListView.LayoutParams(
			ListView.LayoutParams.MATCH_PARENT, DensityUtil.dip2px(90));

	public MemberAdapter(Context context) {
		super(context);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView != null) {
			holder = (ViewHolder) convertView.getTag(R.layout.member_item);
		} else {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.member_item, null);
			convertView.setLayoutParams(layoutParams);
			holder.userHead = (ImageView) convertView
					.findViewById(R.id.user_head);
			holder.nick = (TextView) convertView.findViewById(R.id.nick);
			holder.level = (TextView) convertView.findViewById(R.id.level);
			holder.discount = (TextView) convertView
					.findViewById(R.id.discount);
			holder.balance = (TextView) convertView.findViewById(R.id.balance);
			convertView.setTag(R.layout.member_item, holder);
		}

		Member member = getItem(position);

		ImageLoader.getInstance().load(member.touxiang, holder.userHead);
		holder.nick.setText(member.getDisplay());
		holder.level.setText(String.valueOf(member.dengji));
		holder.discount.setText(String.valueOf(member.zhekoul));
		holder.balance.setText(String.valueOf(member.yue));
		convertView.setContentDescription(member.yonghum);
		return convertView;
	}

	private class ViewHolder {
		public ImageView userHead;
		public TextView nick;
		public TextView level;
		public TextView discount;
		public TextView balance;
	}
}
